#include <string>
#include <io.h>
#include <vector>
#include <WinBase.h>
#include "Global_Include.h"

using namespace std;

typedef void (*ASTCOPYFILE_FUNC)(int, int);

void getFiles(string& dataPath, vector<string>& files)
{
	long long hFile = 0;
	struct _finddata_t fileinfo;
	string p;
	int i = 0;
	if ((hFile = _findfirst(p.assign(dataPath).append("/*").c_str(), &fileinfo)) != -1)
	{
		do
		{
			if ((fileinfo.attrib & _A_SUBDIR))
				continue;
			else
				files.push_back(p.assign(dataPath).append("/").append(fileinfo.name));
		} while (_findnext(hFile, &fileinfo) == 0);
		_findclose(hFile);
	}
}

void CopyDir(
	string& oriPath,
	string& destPath,
	ASTCOPYFILE_FUNC Function
)
//复制文件夹底下的子文件，同样输入相对路径
{
	vector<string> dirFileList;
	int Total = dirFileList.size();
	getFiles(oriPath, dirFileList);

	int Count = 0;
	while (!dirFileList.empty())
	{
		string fileName = dirFileList.back(); //从后往前复制
		size_t Position = fileName.find_last_of('/');
		string prefixName = fileName.substr(Position, fileName.size()); //读取子文件的文件名
		CopyFileA(fileName.c_str(), (destPath + prefixName).c_str(), false);
		dirFileList.pop_back();

		Count++;
		Function(Count, Total);
	}
}